<template>
<!-- 核保处理-列表页面 -->
    <div class="fillcontain" height="800vh">
        <el-form label-width="100px" class="search_container">
            <el-row class="mt10">
                <el-col :span="6">
                    <el-form-item label="受理号：" prop="caseno">
                        <el-input v-model="searchParams.caseno" @blur="chearTrim" placeholder="受理号" clearable></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="保单号：" prop="caseno">
                        <el-input v-model="searchParams.chdrnum" @blur="chearTrim" placeholder="保单号" clearable></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12" class="pl20">
                    <el-button type="primary" icon="el-icon-search" @click="goHeBao"></el-button>
                    <el-button type="primary" plain  icon="el-icon-refresh" @click="resetSearch"></el-button>
                </el-col>
            </el-row>
        </el-form>
        <div class="contain">
          <div class="table_container">
          </div>
        </div>
    </div>
</template>

<script>
    import { mapState, mapGetters } from 'vuex';
    import uwconstant from '@/utils/uwConstants';
    // import { getComCheckList } from "@/api/comInquiry";
    import constant from '@/utils/constant';
	import  {
		isCntainChinese,
	} from "@/api/refund/RefundCommon";
	import {getMysqlInfo,getBranchByUserId} from '@/api/setting'
	import  {
       queryApplnum,policyLockStatus
	} from "@/api/underwriting/uw";
    export default {
        data(){
            return {
				organ:'',
				mysqlUserInfo:{},//中台数据
                searchParams:{
                    caseno:'',
                    chdrnum:''
                },
                loading:false,
             
            }
        },
        created(){
			let userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
			//获取核保员是否是总公司人员
			getMysqlInfo(userInfo.account).then(data =>{
				this.mysqlUserInfo = data;
			});
			getBranchByUserId(userInfo.account).then (data => this.organ = data);
        },
        mounted(){
           
        },
        methods: {
            chearTrim(){
                this.searchParams.caseno = this.searchParams.caseno.trim();
                this.searchParams.chdrnum = this.searchParams.chdrnum.trim();
            },
		async goHeBao(){
                if(this.searchParams.caseno =="" && this.searchParams.chdrnum ==""){
                  this.$message.error("请至少输入一个查询条件！");
                  return;
                }
				if(this.searchParams.caseno !="" ){
					if ( isCntainChinese(this.searchParams.caseno)) {
						this.$message.error("请正确输入受理号！");
						return;
					}
					//判断该单是否被解锁了，是否在建档页面修改过
				 await	this.canGoHeBao(this.searchParams.caseno);
                 
				}
				if(this.searchParams.chdrnum !="" ){
					if ( isCntainChinese(this.searchParams.chdrnum)) {
						this.$message.error("请正确输入保单号！");
						return;
					}
					let params = {
					  "chdrnum":this.searchParams.chdrnum
                    }
                 await queryApplnum(params).then(res => {
                    if (res.resultCode == constant.SUCCESS && res.data !=null) {
					 this.canGoHeBao(res.data);
                      
                    }else{
                      // this.$message.error(res.resultMsg);
                    }
                  }).catch(err => {
                    console.log(err)
                  })

				}

			},
		async canGoHeBao(applnum) {
			let userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
			let params = {
			  "applnum":applnum
			}
			await policyLockStatus(params).then( res =>{
				if (res.resultCode == constant.SUCCESS && res.data !=null) {
					let data = res.data;
					//核保员需求,增加机构校验拦截
					console.log("mysqlInfo"+this.mysqlUserInfo)
					if(this.mysqlUserInfo.headStatus != "0") {
						//如果这个单被这个人锁定了，可以放进去，否则校验
						if(userInfo.account != data.checkUserId &&this.organ != data.organ ){
								//禁止核保
								this.$message({
								    message: '核保员非总公司人员，且本单不是您所属机构的保单，不允许查看 !!',
								    type: 'error'
								});
								return false;
							
						}
						
					}
					if(data.isLock == 'S'){
						this.$message.error("未查到相关数据！");
						return;
					}else if (data.isLock != 'Y') {
						this.$message.error("该受理号处于解锁状态，必须回EUIS操作");
						return;
					} 
					if (data.isChange && data.isChange == 'Y') {
						this.$message.error("该受理号已在建档页面修改数据并保存，必须从建档页面执行核保操作");
						return;
					}
					this.$router.push({path:"/underwrite/info/"+applnum+"/"+uwconstant.pages.tsrk});
				}	
			})	
			},	
            // 清除查询条件
            resetSearch(){
                this.searchParams.caseno = '';
                this.searchParams.chdrnum = '';

            },
          keyEvent() {
            var e = event || window.event;
            if (e && e.keyCode == 113) {
              this.goHeBao();
            }
          },
        },
        computed:{
            ...mapGetters(['tags']),
            reload(){
                return this.$store.state.loading.reload;
            }
        },

      activated() {
        if (this.reload) {
          this.$store.dispatch('loading/CHNAGE_RELOAD', false)
          Object.assign(this.$data, this.$options.data());
        }

        //监听F2 按键事件
        document.addEventListener('keydown', this.keyEvent);
      },
      beforeRouteLeave(to, from, next) {
        document.removeEventListener('keydown', this.keyEvent)
        next();
      },
    }
</script>

<style lang="less" scoped>
    .fillcontain{
        padding-bottom: 0;
    }
    .contain{
        background: #fff;
        padding: 10px;
        margin-bottom: 20px;
    }
   .pagination{
       padding: 10px 20px;
       text-align: right;
   }
   .operationIcon{
        // padding: 12px;
        border:1px solid #e5e5e5;
        border-radius: 50%;
        width: 22px; 
        height: 22px;
        display: inline-block;
        cursor: pointer;
        box-shadow:0 0 3px #f9f9f9;
        .svg-icon{
            font-size: 14px;
            fill:#68a3fc;
        }
   }
   .search_container{
       padding: 20px 20px 0 20px;
   }
</style>



